package com.zlcx.tz.live.service.task;

import com.zlcx.tz.live.repository.DicRepository;
import com.zlcx.tz.live.service.impl.DicServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class TaskDicServiceImpl {

    @Autowired
    private DicRepository dicRepository;
    @Value("${eureka.debug:false}")
    private Boolean debug;

    @Scheduled(cron = "0 0/1 * * * ?")
    public void refreshAll() {
        if (debug) {
            log.warn("本地环境不启动定时");
            return;
        }
        log.debug("刷新全部字典信息");
        dicRepository.findAll().forEach(dic -> DicServiceImpl.dicCache.put(dic.getCode(), dic));
    }

}